
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:just_audio/just_audio.dart';
import 'package:path_provider/path_provider.dart';

class Player {

  static var currentId;
  static final player = AudioPlayer();

  static void play(id) async {
    if (currentId != null && currentId == id) {
      player.stop();
      currentId = null;
      return;
    }
    currentId = id;

    // https://gitee.com/tangbl93/meow/raw/master/audio/13739.mp3
    // var audioURL = "https://gitee.com/tangbl93/meow/raw/master/audio/${id}";
    // await player.setUrl(audioURL);

    var localPath = "audio/${id}";
    await player.setAsset(localPath);

    player.setLoopMode(LoopMode.one);
    player.play();
  }
}